﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace LastfmNet.Models
{
    public class XSPFPlaylistTrack : LastfmModelBase
    {
        public XSPFPlaylistTrack()
        {
            this.Title = string.Empty;
            this.Identifier = string.Empty;
            this.Album = string.Empty;
            this.Creator = string.Empty;
            this.Duration = 0;
            this.Info = string.Empty;
            this.Image = string.Empty;
            this.ArtistPage = string.Empty;
            this.AlbumPage = string.Empty;
            this.TrackPage = string.Empty;
        }

        public XSPFPlaylistTrack(XmlNode playlistTrackNode)
            : this()
        {
            if (playlistTrackNode == null) return;
            this.InitializeFromXmlNode(playlistTrackNode);
        }

        public override void InitializeFromXmlNode(XmlNode node)
        {
            if (node == null) return;
            this.Title = node.GetChildValue("title");
            this.Identifier = node.GetChildValue("identifier");
            this.Album = node.GetChildValue("album");
            this.Creator = node.GetChildValue("creator");
            this.Duration = node.GetChildValue("duration").ToUnsignedInteger();
            this.Info = node.GetChildValue("info");
            this.Image = node.GetChildValue("image");
            this.ArtistPage = node.GetChild("extension").GetChildValue("artistpage");
            this.AlbumPage = node.GetChild("extension").GetChildValue("albumpage");
            this.TrackPage = node.GetChild("extension").GetChildValue("trackpage");
        }

        public string Title
        {
            get;
            set;
        }

        public string Identifier
        {
            get;
            set;
        }

        public string Album
        {
            get;
            set;
        }

        public string Creator
        {
            get;
            set;
        }

        public uint Duration
        {
            get;
            set;
        }

        public string Info
        {
            get;
            set;
        }

        public string Image
        {
            get;
            set;
        }

        public string ArtistPage
        {
            get;
            set;
        }

        public string AlbumPage
        {
            get;
            set;
        }

        public string TrackPage
        {
            get;
            set;
        }
    }
}
